package org.tailor

class DashboardController {
    def scaffold = Dashboard
    def dashboard = {}
    def dashboardClient = {}
    def redirect = {}
    //def twitterService
//Existing dashboard code snipped
/*def tweet = {
def event = Dashboard.get(params.id)
if (event){
twitterService.setStatus(params.status,
    [username:event.twitterId,
password:event.twitterPassword])
}
redirect(action:dashboard, id:dashboard.id)
}*/

    
    /*

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [dashboardInstanceList: Dashboard.list(params), dashboardInstanceTotal: Dashboard.count()]
    }

    def create = {
        def dashboardInstance = new Dashboard()
        dashboardInstance.properties = params
        return [dashboardInstance: dashboardInstance]
    }

    def save = {
        def dashboardInstance = new Dashboard(params)
        if (dashboardInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'dashboard.label', default: 'Dashboard'), dashboardInstance.id])}"
            redirect(action: "show", id: dashboardInstance.id)
        }
        else {
            render(view: "create", model: [dashboardInstance: dashboardInstance])
        }
    }

    def show = {
        def dashboardInstance = Dashboard.get(params.id)
        if (!dashboardInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'dashboard.label', default: 'Dashboard'), params.id])}"
            redirect(action: "list")
        }
        else {
            [dashboardInstance: dashboardInstance]
        }
    }

    def edit = {
        def dashboardInstance = Dashboard.get(params.id)
        if (!dashboardInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'dashboard.label', default: 'Dashboard'), params.id])}"
            redirect(action: "list")
        }
        else {
            return [dashboardInstance: dashboardInstance]
        }
    }

    def update = {
        def dashboardInstance = Dashboard.get(params.id)
        if (dashboardInstance) {
            if (params.version) {
                def version = params.version.toLong()
                if (dashboardInstance.version > version) {
                    
                    dashboardInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'dashboard.label', default: 'Dashboard')] as Object[], "Another user has updated this Dashboard while you were editing")
                    render(view: "edit", model: [dashboardInstance: dashboardInstance])
                    return
                }
            }
            dashboardInstance.properties = params
            if (!dashboardInstance.hasErrors() && dashboardInstance.save(flush: true)) {
                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'dashboard.label', default: 'Dashboard'), dashboardInstance.id])}"
                redirect(action: "show", id: dashboardInstance.id)
            }
            else {
                render(view: "edit", model: [dashboardInstance: dashboardInstance])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'dashboard.label', default: 'Dashboard'), params.id])}"
            redirect(action: "list")
        }
    }

    def delete = {
        def dashboardInstance = Dashboard.get(params.id)
        if (dashboardInstance) {
            try {
                dashboardInstance.delete(flush: true)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'dashboard.label', default: 'Dashboard'), params.id])}"
                redirect(action: "list")
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'dashboard.label', default: 'Dashboard'), params.id])}"
                redirect(action: "show", id: params.id)
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'dashboard.label', default: 'Dashboard'), params.id])}"
            redirect(action: "list")
        }
    }*/
}
